from pydantic_settings import BaseSettings
from typing import Optional
import os

class Settings(BaseSettings):
    # 数据库配置
    DB_HOST: str = "localhost"
    DB_PORT: int = 3306
    DB_USER: str = "root"
    DB_PASSWORD: str = "123456"
    DB_NAME: str = "network_backup"
    
    # 应用配置
    SECRET_KEY: str = "your-secret-key-please-change-in-production"
    APP_HOST: str = "0.0.0.0"
    APP_PORT: int = 8000
    
    # 备份目录（使用绝对路径避免Windows路径问题）
    BACKUP_DIR: str = os.path.abspath("./backups")
    
    # 备份间隔（小时）- 默认24小时
    BACKUP_INTERVAL_HOURS: int = 24
    
    @property
    def DATABASE_URL(self) -> str:
        return f"mysql+pymysql://{self.DB_USER}:{self.DB_PASSWORD}@{self.DB_HOST}:{self.DB_PORT}/{self.DB_NAME}?charset=utf8mb4"
    
    class Config:
        env_file = ".env"
        case_sensitive = True

settings = Settings()

# 确保备份目录存在
os.makedirs(settings.BACKUP_DIR, exist_ok=True)
